package com.designpatterns.GuardedSuspention;

import java.util.LinkedList;

/**
 * Created by 41579 on 2017/6/1.
 */
public class RequestQueue {
    private LinkedList<Request> requestList = new LinkedList<Request>();

    public synchronized Request get() {
        try {
            while (requestList.size() <= 0) {
                System.out.println("waitting for put....");
                wait();
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return requestList.removeFirst();
    }

    public synchronized void put(Request request) {
        System.out.println("put request....");
        requestList.add(request);
        notifyAll();
    }
}
